using Asp.Versioning;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.OData.Query;
using Microsoft.AspNetCore.OData.Results;
using Microsoft.AspNetCore.OData.Routing.Controllers;
using OData.Data;
using OData.Shared.Models;

namespace OData.WebApi.Controller.v1;
[ApiVersion("1.0")]
public class ProductsController(ApplicationDbContext context) : ODataController
{
	[EnableQuery]
	public IQueryable<Product> Get()
	{
		return context.Products;
	}

	[EnableQuery]
	public SingleResult<Product> Get([FromRoute] int key)
	{
		var result = context.Products.Where(p => p.Id == key);
		return SingleResult.Create(result);
	}
}
